<?php

  function sa($param) {
    return array_map('trim', explode(',', $param));
  }
  
  function p($param, $source = false) {
    if ($source) {
      if (is_array($param)) {
        $param = array_map_recursive('htmlspecialchars', $param);
      } else {
        $param = htmlspecialchars($param);
      }
    }
    echo "<pre>";
    print_r($param);
    echo "</pre>\n";
  }
  
  function array_map_recursive($callback, $array) {
    $new_array = array();
    foreach($array as $_key => $_value ) {
      $new_array[$_key] = (is_array($_value ) ? array_map_recursive($callback, $_value) : call_user_func($callback, $_value));
    }
    return $new_array;
  }

  function pcd ($param, $source = false) {
    static $counter;
    if ($source) {
      if (is_object($param)) {
        $param = (array) $param;
      }
      if (is_array($param)) {
        $param = array_map_recursive('htmlspecialchars', $param);
      } else {
        $param = htmlspecialchars($param);
      }
    }
    echo '<pre style="border: 3px solid #ddd; background-color: #f7f7f7; padding: 5px;">';
    print_r($param);
    $counter++;
    echo "\n<a style=\"cursor: pointer;\" onClick=\"div = document.getElementById('backtrace{$counter}'); div.style.display!='block' ? div.style.display='block' : div.style.display='none'\">Show/hide backtrace</a>";
    echo "<pre id=\"backtrace{$counter}\" style=\"display: none; font-size: 11px;\">";
    print_r(debug_backtrace());
    echo "</pre>";
    echo "</pre>\n";
  }
    function espc ($param, $int = '') {    $cont = '';    $temp_int = $def_int = '    ';
    if (is_array($param)) {
      $i = 0;      $cont .= 'Array (';      $cont .= "\n";      foreach ($param as $k => $v) {
        if (intval($k) > 9)
          $temp_int = substr($temp_int, 0, 3);        if (preg_match('/^_/', $k)) {          $cont .= "{$int}{$temp_int}[{$k}] //passed as priv\n";        } else {          $cont .= "{$int}{$temp_int}[{$k}] => ";          $cont .= espc ($v, "{$int}{$def_int}");        }      }      $cont .= $int;      $cont .= ")\n";    } elseif (is_object($param)) {      $cont .= get_class($param). ' (';      $cont .= "\n";            foreach ($param as $k => $v) {
        if (intval($k) > 9)
          $temp_int = substr($temp_int, 0, 3);        if (preg_match('/^_/', $k)) {          $cont .= "{$int}{$temp_int}[{$k}] //passed as priv\n";        } else {          $cont .= "{$int}{$temp_int}[{$k}] => ";          $cont .= espc ($v, "{$int}{$def_int}");        }      }      $cont .= $int;      $cont .= ")\n";          } else {      $cont .= htmlspecialchars($param) . "\n";    }    return $cont;    // This script can freeze once it get to object recurrence... Test prps only  }
    function escl ($param, $int = '') {    //$s = get_object_vars($param);    $cont = '';    if (is_array($param)) {      $cont .= 'Array (';      $cont .= "\n";      foreach ($param as $k => $v) {        if (preg_match('/^_/', $k)) {          $cont .= "{$int}\t[{$k}] //passed as priv\n";        } else {          $cont .= "{$int}\t[{$k}] => ";          $cont .= espc ($v, "{$int}\t");        }      }      $cont .= $int;      $cont .= ")\n";
    } elseif (is_object($param)) {      $cont .= get_class($param). ' (';      $cont .= "\n";            foreach ($param as $k => $v) {        if (preg_match('/^_/', $k)) {          $cont .= "{$int}\t[{$k}] //passed as priv\n";        } else {          $cont .= "{$int}\t[{$k}] => ";          $cont .= espc ($v, "{$int}\t");        }      }      $cont .= $int;      $cont .= ")\n";          } else {      $cont .= $param . "\n";    }    return $cont;    // This script can freeze once it get to object recurrence... Test prps only  }        function pc ($param) {    echo '<pre>';      //print_r (debug_backtrace());      echo espc($param);    echo '</pre>';  }          function spc ($param, $source = false) {
    if ($source) {
      if (is_object($param)) {
        $param = (array) $param;
      }
      if (is_array($param)) {
        $param = array_map_recursive('htmlspecialchars', $param);
      } else {
        $param = htmlspecialchars($param);
      }
    }
    echo '<pre style="border: 3px solid #ddd; background-color: #f7f7f7; padding: 5px;">';
    //Akrudo::raise_warning(debug_backtrace());
    print_r($param);
    echo "</pre>\n";
  }
  
  function logger() {
    return $GLOBALS['Nails']->log;
  }
  
  function nails() {
    return $GLOBALS['Nails'];
  }
  
  function substr_after($str, $after) {
    return substr($str, (strpos($str, $after) + strlen($after)));
  }
    
  function substr_before($str, $before) {
    return substr($str, 0, (strpos($str, $before)));
  }
  
  function array_flip_merge ($array) {
    $returned_array = array();
    foreach ($array as $array_element) {
      $returned_array = array_merge_recursive($returned_array, $array_element);
    }
    return $returned_array;
  }
  
  function array_combine_flipped ($array) {
    $keys = array_keys($array);    if (count($array[$keys[0]]) <= 1) {      return array($array[$keys[0]] => $array[$keys[1]]);    } else {      return array_combine($array[$keys[0]], $array[$keys[1]]);    }
  }
  
  function array_flip_merge_combine ($array) {
    return array_combine_flipped (array_flip_merge($array));
  }
  
  function array_rotate ($array) {
    return array_flip_merge_combine((array) $array);
  }    function string2filename($AStr) {    $tmp = $AStr;
    $tmp = pl_iso2win($tmp);    $tmp = pl_win2ascii($tmp);    $tmp = strtolower($tmp);    $tmp = ereg_replace("[^a-z0-9]", "_", $tmp);    $tmp = ereg_replace("__+", "_", $tmp);    $tmp = trim($tmp, '_');    return $tmp;  }
  
  class Utility {
    
    function add_placeholder ($arg) {
      return $arg . ' = ?';
    }
    
  }
  
?>